package com.itheima.stock.controller.V1;

import com.itheima.stock.annotation.Limter;
import com.itheima.stock.api.UserConreollerApi;
import com.itheima.stock.dto.LoginDTO;
import com.itheima.stock.enums.CodeEnum;
import com.itheima.stock.exception.Exceptions;
import com.itheima.stock.response.ResponseResult;
import com.itheima.stock.service.UserServise;
import com.itheima.stock.vo.CaptchaVo;
import com.itheima.stock.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController implements UserConreollerApi {
    @Autowired
    private UserServise userServise;


    @Override
    public ResponseResult<LoginVO> login(LoginDTO loginDTO) {

        return ResponseResult.ok(userServise.login(loginDTO));
    }

    @Limter
    @Override
    public ResponseResult<CaptchaVo> getCaptcha() {
        return ResponseResult.ok(userServise.getCaptcha());
    }

    @Override
    public String sayHello(String name) {

        Exceptions.cast(CodeEnum.DATA_ERROR);
        return "Hello " + name;
    }
}
